function numberToChinese(num) {
    const chineseDigits = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
    const chineseUnits = ['', '拾', '佰', '仟'];
    const chineseBigUnits = ['', '万', '亿'];
    const decimalUnits = ['角', '分'];

    // 处理非数字和负数
    if (isNaN(num) || num < 0) return '无效输入';
    num = Number(num).toFixed(2);
    let [integerPart, decimalPart] = num.split('.');

    // 转换整数部分
    let result = '';
    let groupIndex = 0;
    for (let i = integerPart.length - 1; i >= 0; i -= 4) {
        let group = integerPart.slice(Math.max(0, i - 3), i + 1);
        let groupStr = '';
        for (let j = 0; j < group.length; j++) {
            let digit = parseInt(group[j]);
            let unit = chineseUnits[j];
            if (digit !== 0) {
                groupStr = chineseDigits[digit] + unit + groupStr;
            } else if (groupStr[0] !== '零') {
                groupStr = chineseDigits[digit] + groupStr;
            }
        }
        groupStr = groupStr.replace(/零+/g, '零').replace(/零$/, '');
        if (groupStr !== '') groupStr += chineseBigUnits[groupIndex];
        result = groupStr + result;
        groupIndex++;
    }

    // 处理小数部分
    let decimalStr = '';
    for (let i = 0; i < 2; i++) {
        let digit = parseInt(decimalPart[i]);
        if (digit !== 0) decimalStr += chineseDigits[digit] + decimalUnits[i];
    }

    // 组合结果
    result = result.replace(/^零+/, '') || '零';

    return result + '元' + (decimalStr || '整');
}
